import { ECareer } from "../../../../../Message/Public/ECareer";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { GModuleEvent } from "../../../mvc/GModuleEvent";
import { LookupPlayerData } from "../LookupPlayerData";
import { Cache } from "../../../cache/Cache";
import { CareerUtil } from "../../common/util/CareerUtil";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { EquipmentUtil } from "../../common/util/EquipmentUtil";
import { EquipmentPanel } from "./EquipmentPanel";
import { EquipsPanel } from "./EquipsPanel";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { PlayerSuitPanel } from "./PlayerSuitPanel";
import { FightSpiritBtn } from "../../fightSpirit/FightSpiritBtn";
import { Global } from "../../../../../com/gengine/global/Global";
import { CallLater } from "../../../../common/net/CallLater";
import { LongProgressBar } from "../LongProgressBar";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GuideArrowManager } from "../../../manager/GuideArrowManager";
import { EffectManager } from "../../../manager/EffectManager";
import { MedalPanel } from "./MedalPanel";
import { EVIPType } from "../../../../../Message/Public/EVIPType";
import { GTabBar } from "../../../../../com/mui/controls/GTabBar";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class RoleEquipInfoPanel
    
    export  class RoleEquipInfoPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        /* internal  */onResLoaded(): void
        {
            var loc1=this.getCurCareer();
            if (!(loc1 == ECareer._ECareerNewPlayer) && !(loc1 == ECareer._ECareerNo)) 
            {
                if (this._careerImg) 
                {
                    this._careerImg.bitmapData = GlobalClass.getBitmapData("CareerImg_" + loc1);
                }
            }
            return;
        }

        public set mode(arg1: string)
        {
            this._mode = arg1;
            this._equipmentPanel.mode = arg1;
            this._equipsPanel.mode = arg1;
            this._playerSuit.mode = arg1;
            this._fightSpirit.mode = arg1;
            if (arg1 != GModuleEvent.Mode_PreSecondCareer) 
            {
                this._txtJingYan.visible = true;
                if (!this._jingyanBar.parent) 
                {
                    this.addChild(this._jingyanBar);
                }
            }
            else if (this._jingyanBar.parent) 
            {
                this._jingyanBar.parent.removeChild(this._jingyanBar);
                this._txtJingYan.visible = false;
            }
            return;
        }

        public get mode(): string
        {
            return this._mode;
        }

        /* internal  */updateCareerTabData(): void
        {
            var loc2=null;
            var loc3=0;
            var loc4=0;
            var loc5=0;
            var loc1=new Array<any>();
            if (this.mode != GModuleEvent.Mode_Self) 
            {
                if (this.mode == GModuleEvent.Mode_Other && LookupPlayerData.lookupData) 
                {
                    loc3 = LookupPlayerData.lookupData.miniPlayer.career;
                    loc4 = LookupPlayerData.lookupData.secondCareer;
                    loc5 = LookupPlayerData.lookupData.miniPlayer.careerEnable;
                }
            }
            else 
            {
                loc3 = Cache.instance.role.careerBasic;
                loc4 = Cache.instance.role.careerSecond;
                loc5 = Cache.instance.role.careerEnabled;
            }
            loc2 = new Object();
            loc2.career = loc3;
            loc2.enable = loc3 == loc5;
            loc2.name = CareerUtil.getCareerName(loc3);
            loc2.label = loc2.name;
            loc1.push(loc2);
            loc2 = new Object();
            loc2.career = loc4;
            loc2.enable = loc4 == loc5;
            loc2.name = CareerUtil.getCareerName(loc4);
            loc2.label = loc2.name;
            loc1.push(loc2);
            this._careerTabBar.dataProvider = loc1;
            if (loc3 != loc5) 
            {
                this._careerTabBar.selectedIndex = 1;
            }
            else 
            {
                this._careerTabBar.selectedIndex = 0;
            }
            this.onCareerTabBarChangeHandler();
            return;
        }

        /* internal  */onCareerTabBarChangeHandler(arg1=null): void
        {
            if (this._careerTabBar.selectedItem) 
            {
                if (this._careerTabBar.selectedItem["enable"]) 
                {
                    this._equipmentPanel.addFilters(false);
                    this._equipsPanel.addFilters(false);
                }
                else 
                {
                    this._equipmentPanel.addFilters(true);
                    this._equipsPanel.addFilters(true);
                }
            }
            this.updateEquipmentInfos();
            return;
        }

        /* internal  */updateEquipmentInfos(): void
        {
            var loc2=null;
            var loc1=this.getCurCareer();
            if (loc1 != this._career) 
            {
                loc2 = this._equipmentSecondCareer;
            }
            else 
            {
                loc2 = this._equipment;
            }
            if (this.mode != GModuleEvent.Mode_Self) 
            {
                this._equipmentPanel.updateRoleInfo(loc2, loc1, this._camp, this._sex, this._wxType, this._fashionState, this._wingState, this._fashionWeaponState, this._surroundState, this._waistBeltState, this._elfState);
                this._equipsPanel.curCareer = loc1;
                this._equipsPanel.setEquipments(loc2);
                this._equipsPanel.updateAddInfos();
            }
            else 
            {
                this._playerSuit.curCareer = loc1;
                this.updateSuitPanel();
                this._equipmentPanel.curCareer = loc1;
                this._equipmentPanel.updateSelfInfo();
                this._equipsPanel.curCareer = loc1;
                this._equipsPanel.setEquipments(Cache.instance.pack.rolePackCache.getAllItemsByCareer(loc1));
                this._equipsPanel.updateAddInfos();
                if (loc1 != Cache.instance.role.entityInfo.career) 
                {
                    if (this._equipmentSecondCareer) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.FightSpiritUpdateBtnToolTips, EquipmentUtil.getCurRolePackEquipsData(this._equipmentSecondCareer)));
                    }
                }
                else if (this._equipment) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FightSpiritUpdateBtnToolTips, EquipmentUtil.getCurRolePackEquipsData(this._equipment)));
                }
            }
            return;
        }

        public updataIsShowFashion(): void
        {
            var loc1=false;
            if (Cache.instance.role.isShowFashion <= 0) 
            {
                loc1 = true;
            }
            else 
            {
                loc1 = false;
            }
            this._equipmentPanel.showFashionCheckBox.selected = loc1;
            return;
        }

        protected initUI(): void
        {
            this._equipmentPanel = new EquipmentPanel();
            this.addChild(this._equipmentPanel);
            this._equipsPanel = new EquipsPanel();
            this.addChild(this._equipsPanel);
            var loc1=ObjCreate.createBg(43, 0, 168, 25, this, ImagesConst.PopUpMenuOverSkin);
            this._playerName = ObjCreate.createTextField("", 43, 5, 168, 20, this);
            this._playerName.defaultTextFormat = new GTextFormat("", 12, 15859633, null, null, null, null, null, flash.text.TextFieldAutoSize.CENTER);
            this._levelTxt = ObjCreate.createGTextField("LV·", 205, 5, 60, 20, this, GlobalStyle.textFormat6);
            this._jingyanBar = this.createProgressBars(Language.getString(30014), 2, "EnergyBar");
            this._playerSuit = new PlayerSuitPanel();
            this._playerSuit.x = 58;
            this._playerSuit.y = 78;
            addChild(this._playerSuit);
            this._fightSpirit = new FightSpiritBtn();
            this._fightSpirit.x = 53;
            this._fightSpirit.y = 159;
            addChild(this._fightSpirit);
            this._fightSpirit.addEventListener(flash.events.MouseEvent.CLICK, this.onFighSpiritBtn);
            this._fightSpirit.visible = false;
            if (Global.isDebugModle) 
            {
                this._fightSpirit.visible = true;
            }
            this.showVipImg();
            CallLater.addCallBack(this.updateCareerUI);
            return;
        }

        public updateIsShowWing(): void
        {
            var loc1=false;
            if (Cache.instance.role.isShowWing <= 0) 
            {
                loc1 = true;
            }
            else 
            {
                loc1 = false;
            }
            this._equipmentPanel.showWingCheckBox.selected = loc1;
            return;
        }

        public updateIsShowFashionWeapon(): void
        {
            var loc1=false;
            if (Cache.instance.role.isShowFashionWeapon <= 0) 
            {
                loc1 = true;
            }
            else 
            {
                loc1 = false;
            }
            this._equipmentPanel.showFashWeaponCheckBox.selected = loc1;
            return;
        }

        public updateIsShowFootPrint(): void
        {
            var loc1=false;
            if (Cache.instance.role.isShowFootPrint <= 0) 
            {
                loc1 = true;
            }
            else 
            {
                loc1 = false;
            }
            this._equipmentPanel.showFootPrintCheckBox.selected = loc1;
            return;
        }

        public updateIsShowBubble(): void
        {
            var loc1=false;
            if (Cache.instance.role.isShowBubble <= 0) 
            {
                loc1 = true;
            }
            else 
            {
                loc1 = false;
            }
            this._equipmentPanel.showBubbleCheckBox.selected = loc1;
            return;
        }

        public updateIsShowSurround(): void
        {
            var loc1=false;
            if (Cache.instance.role.isShowSurround <= 0) 
            {
                loc1 = true;
            }
            else 
            {
                loc1 = false;
            }
            this._equipmentPanel.showSurroundCheckBox.selected = loc1;
            return;
        }

        public updateIsShowWaistBelt(): void
        {
            var loc1=false;
            if (Cache.instance.role.isShowWaistBelt <= 0) 
            {
                loc1 = true;
            }
            else 
            {
                loc1 = false;
            }
            this._equipmentPanel.showWaistBeltCheckBox.selected = loc1;
            return;
        }

        public updateIsShowElf(): void
        {
            var loc1=false;
            if (Cache.instance.role.isShowElf <= 0) 
            {
                loc1 = true;
            }
            else 
            {
                loc1 = false;
            }
            this._equipmentPanel.showElfCheckBox.selected = loc1;
            return;
        }

        public updateEquip(): void
        {
            this._equipmentPanel.updateSelfInfo();
            return;
        }

        /* internal  */createProgressBars(arg1: string, arg2: int, arg3: string): LongProgressBar
        {
            this._txtJingYan = ObjCreate.createTextField("", 50, 271 + arg2 * 18, 40, 20, this);
            this._txtJingYan.htmlText = "<font color=\'#ffff00\'>" + arg1 + "</font>";
            var loc1;
            (loc1 = new LongProgressBar()).x = 85;
            loc1.y = 273 + arg2 * 18;
            loc1.progressBarClass = arg3;
            loc1.setValue(1, 10);
            loc1.setBgSize(115, 14);
            this.addChild(loc1);
            return loc1;
        }

        public updateInfos(arg1: string=null, arg2: int=-1, arg3: int=-1): void
        {
            if (arg1) 
            {
                this._playerName.text = arg1;
            }
            if (arg2 != -1) 
            {
                this._career = arg2;
                if (this._careerImg) 
                {
                    this._careerImg.bitmapData = null;
                }
                LoaderHelp.addResCallBack(ResFileConst.careerImg, this.onResLoaded);
            }
            if (arg3 != -1) 
            {
                this._levelTxt.htmlText = "Lv·<font size=\'13\'>" + arg3 + "</font>";
            }
            this.updateMedelShow(arg3);
            return;
        }

        public updateSexChange(): void
        {
            this._equipmentPanel.updateSelfInfo();
            return;
        }

        public updateSuitPanel(): void
        {
            if (this._playerSuit != null) 
            {
                this._playerSuit.updateSuitState(this._mode);
                this._playerSuit.updateSkillState(this._mode);
            }
            return;
        }

        public updateSuitSkillRate(): void
        {
            if (this._playerSuit != null) 
            {
                this._playerSuit.updateSuitSkillRate();
            }
            return;
        }

        public updateMedal(): void
        {
            if (this._medal) 
            {
                this._medal.updateMedal();
            }
            return;
        }

        public guideMedal(): void
        {
            if (this._medal) 
            {
                this._medal.guideMedal();
            }
            return;
        }

        public setEquipments(arg1: Array<any>, arg2: int, arg3: Array<any>, arg4: int, arg5: int=-1, arg6: int=-1, arg7: int=0, arg8: Boolean=false, arg9: Boolean=false, arg10: Boolean=false, arg11: Boolean=false, arg12: Boolean=false, arg13: Boolean=false): void
        {
            this._equipment = arg1;
            this._career = arg2;
            this._equipmentSecondCareer = arg3;
            this._secondCareer = arg4;
            this._camp = arg5;
            this._sex = arg6;
            this._wxType = arg7;
            this._fashionState = arg8;
            this._wingState = arg9;
            this._fashionWeaponState = arg10;
            this._surroundState = arg11;
            this._waistBeltState = arg12;
            this._elfState = arg13;
            this.updateEquipmentInfos();
            return;
        }

        public updateFightSpirit(arg1: Array<any>, arg2: int, arg3: int): void
        {
            var loc1=0;
            var loc2=null;
            if (this.mode != GModuleEvent.Mode_Self) 
            {
                this._fightSpirit.updateTips(arg1, arg2, arg3);
            }
            else 
            {
                loc1 = this.getCurCareer();
                arg2 = Cache.instance.role.fightSpiritLevel;
                loc2 = [];
                if (loc1 != Cache.instance.role.entityInfo.career) 
                {
                    loc2 = EquipmentUtil.getCurRolePackEquipsData(Cache.instance.pack.rolePackCache.getSecondCareerEquips());
                }
                else 
                {
                    loc2 = EquipmentUtil.getCurRolePackEquipsData(Cache.instance.pack.rolePackCache.getFirstCareerEquips());
                }
                this._fightSpirit.updateTips(loc2, arg2, arg3);
            }
            return;
        }

        public showFightSpirit(arg1: int): void
        {
            if (Global.isDebugModle) 
            {
                this._fightSpirit.visible = true;
                return;
            }
            if (arg1 != 1) 
            {
                this._fightSpirit.visible = false;
            }
            else 
            {
                this._fightSpirit.visible = true;
            }
            return;
        }

        public guideFightSpirit(): void
        {
            var loc1=GuideArrowManager.getGuideArrow(GuideArrowManager.Dir_R, null, 0);
            loc1.x = 41;
            loc1.y = 175;
            addChild(loc1);
            if (this._fightSpirit.visible) 
            {
                EffectManager.glowFilterReg(this._fightSpirit);
            }
            return;
        }

        protected onFighSpiritBtn(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (GuideArrowManager.guideArrow.parent == this) 
            {
                GuideArrowManager.hideGuideArrow();
            }
            EffectManager.glowFilterUnReg(this._fightSpirit);
            return;
        }

        public updateMedelShow(arg1: int): void
        {
            if (arg1 >= 65) 
            {
                if (this._medal == null) 
                {
                    this._medal = new MedalPanel();
                    this._medal.x = 60;
                    this._medal.y = 133;
                }
                this._medal.mode = this._mode;
                addChild(this._medal);
            }
            else if (this._medal && this._medal.parent) 
            {
                removeChild(this._medal);
            }
            return;
        }

        public updateFashionJewelInfo(arg1: Array<any>, arg2: int): void
        {
            if (this._equipsPanel) 
            {
                this._equipsPanel.updateFashionJewelInfo(arg1, arg2);
            }
            return;
        }

        public updateFashionFlyLv(arg1: int, arg2: int): void
        {
            if (this._equipsPanel) 
            {
                this._equipsPanel.flyLv = arg1;
                this._equipsPanel.curLv = arg2;
            }
            return;
        }

        /* internal  */getCurCareer(): int
        {
            var loc1=0;
            if (this._hasTwoCareer) 
            {
                return this._careerTabBar.selectedItem["career"];
            }
            if (this.mode != GModuleEvent.Mode_Self) 
            {
                if (this.mode != GModuleEvent.Mode_Other) 
                {
                    if (this.mode != GModuleEvent.Mode_ArenaCross) 
                    {
                        if (this.mode != GModuleEvent.Mode_Wrestle) 
                        {
                            loc1 = this._career;
                        }
                        else if (LookupPlayerData.wrestleLookInfo) 
                        {
                            loc1 = LookupPlayerData.wrestleLookInfo.miniPlayer.careerEnable;
                        }
                    }
                    else if (LookupPlayerData.arenaCrossLookInfo) 
                    {
                        loc1 = LookupPlayerData.arenaCrossLookInfo.miniPlayer.careerEnable;
                    }
                }
                else if (LookupPlayerData.lookupData) 
                {
                    loc1 = LookupPlayerData.lookupData.miniPlayer.careerEnable;
                }
            }
            else 
            {
                loc1 = Cache.instance.role.entityInfo.career;
            }
            return loc1;
        }

        public updateOtherEquipments(): void
        {
            this._equipsPanel.setOtherEquipments();
            return;
        }

        public updateAddInfos(): void
        {
            this._equipsPanel.updateAddInfos();
            return;
        }

        public updateExp(arg1: number, arg2: number): void
        {
            this._jingyanBar.setPercentValue(arg2, arg1);
            return;
        }

        public showVipImg(arg1: int=-1): void
        {
            var loc1=null;
            if (!(this._VIPImg == null) && this._VIPImg.parent) 
            {
                removeChild(this._VIPImg);
                this._VIPImg = null;
            }
            if (arg1 != -1) 
            {
                if (arg1 != EVIPType._EVIPTypeWeek) 
                {
                    if (arg1 != EVIPType._EVIPTypeMonth) 
                    {
                        if (arg1 == EVIPType._EVIPTypeHalfYear) 
                        {
                            this._VIPImg = GlobalClass.getBitmap(ImagesConst.VIP3);
                        }
                    }
                    else 
                    {
                        this._VIPImg = GlobalClass.getBitmap(ImagesConst.VIP2);
                    }
                }
                else 
                {
                    this._VIPImg = GlobalClass.getBitmap(ImagesConst.VIP1);
                }
            }
            else if (Cache.instance.vip.vipInfo != null) 
            {
                loc1 = Cache.instance.vip.vipInfo.VIPType;
                if (loc1.value() != EVIPType._EVIPTypeWeek) 
                {
                    if (loc1.value() != EVIPType._EVIPTypeMonth) 
                    {
                        if (loc1.value() == EVIPType._EVIPTypeHalfYear) 
                        {
                            this._VIPImg = GlobalClass.getBitmap(ImagesConst.VIP3);
                        }
                    }
                    else 
                    {
                        this._VIPImg = GlobalClass.getBitmap(ImagesConst.VIP2);
                    }
                }
                else 
                {
                    this._VIPImg = GlobalClass.getBitmap(ImagesConst.VIP1);
                }
            }
            if (this._VIPImg != null) 
            {
                this._VIPImg.x = 93;
                this._VIPImg.y = 25;
                addChild(this._VIPImg);
            }
            return;
        }

        public updateCareerUI(): void
        {
            if (this.mode == GModuleEvent.Mode_Self && Cache.instance.role.hasSecondCareer) 
            {
                this._hasTwoCareer = true;
                if (!this._careerTabBar) 
                {
                    this._careerTabBar = ObjCreate.createGTabBar(3, 2, [], 38, 20, null, this.onCareerTabBarChangeHandler);
                    this._careerTabBar.horizontalGap = 0;
                    this._careerTabBar.buttonStyleName = "RoleCareerTabBtn";
                }
                addChild(this._careerTabBar);
                this.updateCareerTabData();
                if (this._careerImg && this._careerImg.parent) 
                {
                    this._careerImg.parent.removeChild(this._careerImg);
                }
            }
            else 
            {
                this._hasTwoCareer = false;
                if (!this._careerImg) 
                {
                    this._careerImg = new Object /* flash.display.Bitmap */();
                    this._careerImg.x = 5;
                    this._careerImg.y = 2;
                }
                addChild(this._careerImg);
                LoaderHelp.addResCallBack(ResFileConst.careerImg, this.onResLoaded);
                if (this._careerTabBar && this._careerTabBar.parent) 
                {
                    this._careerTabBar.parent.removeChild(this._careerTabBar);
                }
            }
            return;
        }

        /* internal */ /* var */_mode: string;

        /* internal */ /* var */_careerTabBar: GTabBar;

        /* internal */ /* var */_equipmentPanel: EquipmentPanel;

        /* internal */ /* var */_equipsPanel: EquipsPanel;

        /* internal */ /* var */_VIPImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_careerImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_levelTxt: GTextFiled;

        /* internal */ /* var */_jingyanBar: LongProgressBar;

        /* internal */ /* var */_txtJingYan: Object /* flash.text.TextField */;

        /* internal */ /* var */_playerSuit: PlayerSuitPanel;

        /* internal */ /* var */_medal: MedalPanel;

        /* internal */ /* var */_fightSpirit: FightSpiritBtn;

        /* internal */ /* var */_playerName: Object /* flash.text.TextField */;

        /* internal */ /* var */_equipment: Array<any>;

        /* internal */ /* var */_career: int;

        /* internal */ /* var */_equipmentSecondCareer: Array<any>;

        /* internal */ /* var */_secondCareer: int;

        /* internal */ /* var */_camp: int;

        /* internal */ /* var */_wxType: int;

        /* internal */ /* var */_fashionState: Boolean;

        /* internal */ /* var */_wingState: Boolean;

        /* internal */ /* var */_fashionWeaponState: Boolean;

        /* internal */ /* var */_surroundState: Boolean;

        /* internal */ /* var */_waistBeltState: Boolean;

        /* internal */ /* var */_elfState: Boolean;

        /* internal */ /* var */_hasTwoCareer: Boolean;

        /* internal */ /* var */_sex: int;
    }
